//
//  AlertViewController.swift
//  DaRings
//
//  Created by 尹琼 on 2022/12/14.
//

import UIKit
import MYModule

open class AlertViewController: ViewController {
    
    public var customView: View
    
    public var confirmAction: AlertAction?
    public var cannelAction: AlertAction?
    
    init(customView: View, confirm: AlertActionHandler? = nil, cancel: AlertActionHandler? = nil) {
        
        self.customView = customView
        
        if let confirm = confirm {
            confirmAction = AlertAction(type: .confirm(title: "dialog_confirm".language, color: UIColor.blue), handler: confirm)
        }
        
        if let cancel = cancel {
            cannelAction = AlertAction(type: .cancel(title: "page_cancel".language, color: UIColor.red), handler: cancel)
        }
        
        super.init(nibName: nil, bundle: nil)
        
        modalType()
        
    }
    
    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

    open override func viewDidLoad() {
        super.viewDidLoad()
        

       
    }
    
   func modalType() {
        
        self.modalTransitionStyle = .crossDissolve
        self.modalPresentationStyle = .fullScreen
        self.view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
        
    }
    
    open override func makeUI() {
        super.makeUI()
        
        
        
        
    }
    

}

extension AlertViewController {
    
    
    typealias AlertActionHandler = ((_ alertViewController: AlertViewController, _ action: AlertAction) ->Void)
    
    public enum AlertActionType {
        
        case confirm(title: String, color: UIColor)
        case cancel(title: String, color: UIColor)
        
    }
    
    public struct AlertAction {
        var type: AlertActionType
        var handler: (AlertActionHandler)?
        
    }
    
}
